'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    const { INTEGER, DATE, STRING, ENUM } = Sequelize;
    await queryInterface.createTable('apply',{
      id: {type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true},
      user_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '用户id',
        // 定义外键
        references: {
          model: 'user',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      friend_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '好友id',
        // 定义外键
        references: {
          model: 'user',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      nickname: { type: STRING(30), allowNull: false, defaultValue: '', comment: '备注' },
      lookme: { type: INTEGER(1), allowNull: false, defaultValue: 1, comment: '看我'},
      lookhime: { type: INTEGER(1), allowNull: false, defaultValue: 1, comment: '看他' },
      status: { type: ENUM,
        // 用户未操作，被用户拒绝，同意，忽略
        values: ['pending','refuse','agree','ignore'], 
        allowNull: false, defaultValue: 'pending', comment: '申请状态' },
      created_at: DATE,
      updated_at: DATE
    });
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('apply');
  }
};
